﻿using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class OleObjectSizeRecord : WorksheetLevelRecord
    {
        private ushort unused;
        private RefU refu;

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.OleObjectSize; }
        }

        internal override void Apply(BiffReaderWorksheetContext context)
        {
            RangeAddress a = (RangeAddress) refu;
            context.Worksheet.Selection = Range.Create(context.Worksheet, a, false);
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            context.WriteUInt16(unused);
            this.refu.Write(context.Writer);
        }

        protected override void ReadContent(BiffReaderContext context, int length)
        {
            Contract.Ensures(context.BaseStream.Position == Contract.OldValue(context.BaseStream.Position) + length);
            this.unused = context.ReadUInt16();
            this.refu = new RefU();
            this.refu.Read(context.Reader);

        }
    }
}